package com.sharding.demo.nproxy.config;

import org.springframework.beans.factory.FactoryBean;

/**
 * @Author hu xu hong
 * @Date 2023/4/3 11:49
 */
public class LearnFactoryBean<T> implements FactoryBean<T> {

    private Class<T> mapperInterface;

    public LearnFactoryBean() {
        // intentionally empty
    }

    public LearnFactoryBean(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    private MapperProxyFactory<T> mapperProxyFactory = new MapperProxyFactory();

    @Override
    public T getObject() throws Exception {
        return mapperProxyFactory.newInstance(mapperInterface);
    }

    @Override
    public Class<?> getObjectType() {
        return this.mapperInterface;
    }
}
